/*
   Zii EGGxplorer - A simple Zii file browser

   Copyright (C) 2009 - 2010 Claudio Corti

   Header file for PathInfo class: returns informations about a path and is the path is a directory,
   it allows browsing of the content.
*/

#ifndef _PATHINFO_H_
#define _PATHINFO_H_

// Unix standard headers
#include <dirent.h>
#include <time.h>

// Type of path
enum PathType
{
   BlockDevice = 0,
   CharacterDevice,
   Directory,
   Pipe,
   RegularFile,
   Socket,
   WhiteOut,
   Unknown,
   SymbolicLink
};

class PathInfo
{
public:
   // Constructor
   PathInfo(char *);

   // Destructor
   ~PathInfo();

   // Store information about the path; true if none error occurred
   bool QueryInfo();

   // Return the next file or folder contained by the directory, or NULL if: this is a file, the
   // directory is empty or end of the stream is reached
   PathInfo *Next();    // Need to manually delete returned PathInfo pointer

   // If DoQuery is false or Next is NULL, return the error occurred
   char *GetError();        // No need to manually delete the returned string
   char *GetError(int *);   // No need to manually delete the returned string

   // Getters
   char     *GetPathName();     // No need to manually delete the returned string
   char     *GetParentName();   // No need to manually delete the returned string
   char     *GetBaseName();     // No need to manually delete the returned string

   char     *GetLinkedPath();   // No need to manually delete the returned string

   int       GetSize();

   char     *GetCreationTime(char *);       // Need to manually delete the returned string
   char     *GetAccessTime(char *);         // Need to manually delete the returned string
   char     *GetModificationTime(char *);   // Need to manually delete the returned string

   bool      TypeIs(unsigned char );
   unsigned char GetType();

private:
   char           *error_str;            // Error description string of errno code
   int             error_number;         // errno code
   char           *full_path;            // The path pointed by the instance of the class
   char           *parent_path;          // The parent directory of this path
   char           *linked_path;          // Path of the pointed file is this is a link
   short           base_name_position;   // Position of last directory separator
   short           path_len;             // Length of full_path

   unsigned char   path_type;            // Type of the file pointed by full_path
   int             size;                 // For files, the size in bytes; for directories, the
                                         // number of elements contained in it
   timespec        creation_time;        // Date and time of creation
   timespec        access_time;          // Date and time of last access
   timespec        modification_time;    // Date and time of last modification

   DIR            *directory_stream;     // If this is a directory, this represent the stream from
                                         // from which the content can be accessed

   // Get the path of the file pointed by a symbolic link
   bool get_linked_path();
};

struct PathInfoPtrNameComparator
{
   bool operator()(PathInfo *, PathInfo *);
};


#endif   /* _PATHINFO_H_ */
